home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Development Tools & Languages / Dylan Related / Marlais / MacMarlais 0.5.9d46 / Examples / Window-Menu.dyl < prev    next >
Encoding:
Text File  |  1995-02-12  |  2.8 KB  |  100 lines  |  [TEXT/Mrls]

  1. module:        dylan-user
  2. description:    example of using window graphics and menus.
  3.  
  4. // need a require form to prevent multiple loads.
  5. load("Windows.dyl");
  6. load("Menus.dyl");
  7.  
  8. /*
  9. define module Window-Menu
  10.     use dylan-user, export: all;
  11.     use Windows, export: all;
  12.     use Menus, export: all;
  13. end module Window-Menu;
  14. */
  15.  
  16. define constant line-window-updater = method (window :: <window>)
  17.     let bounds = window.bounds;
  18.     let width = bounds[3] - bounds[1];    // right - left;
  19.     let half-width = truncate/ (width, 2);
  20.     let height = bounds[2] - bounds[0];    // bottom - top;
  21.     let half-height = truncate/ (height, 2);
  22.     window-erase(window);
  23.     window-draw-line(window, vector(0, 0, height, width));
  24.     window-draw-line(window, vector(height, 0, 0, width));
  25.     window-draw-line(window, vector(half-height, 0, half-height, width));
  26.     window-draw-line(window, vector(0, half-width, height, half-width));
  27.     window-move-to(window, 0, half-height);
  28.     window-draw-string(window, "Text!");
  29. end method;
  30.  
  31. define constant make-line-window = method ()
  32.     // create a new window. windows are initially invisible by default.
  33.     let window = make(<window>,
  34.                     title: "Graphics",
  35.                     bounds: #[50, 10, 250, 310],
  36.                     updater: line-window-updater);
  37.     // set up some attributes. a 3x3 pen.
  38.     window.pen-size := #[3, 3];
  39.     // use Geneva-24, bold, extend, italic.
  40.     window.text-style := make(<text-style>, font: "Geneva",
  41.                         size: 24, face: $bold + $extend + $italic);
  42.     // make the window visible.
  43.     window.visible := #t;
  44.     window;
  45. end method;
  46.  
  47. // create a menu that controls windows.
  48.  
  49. define constant window-menu-behavior = method (menu :: <menu>, item :: <string>)
  50.     if (item = "Create")
  51.         make-line-window();
  52.     else
  53.         let window = front-window();
  54.         if (window)
  55.             if (item = "Destroy")
  56.                 window-dispose(window);
  57.             else
  58.                 window.visible := (item = "Show");
  59.             end if;
  60.         end if;
  61.     end if;
  62. end method;
  63.  
  64. define constant window-menu-adjuster = method (menu :: <menu>)
  65.     let items = #("Destroy", "Show", "Hide");
  66.     let state = (front-window() ~= #f);
  67.     menu-set-item-states(menu, items, list(state, state, state));
  68. end method;
  69.  
  70. define constant make-window-menu  = method ()
  71.     let menu = make(<menu>, title: "Window", id: 1000,
  72.                     items: #("Create", "Destroy", "-", "Show", "Hide"),
  73.                     behavior: window-menu-behavior,
  74.                     adjuster: window-menu-adjuster);
  75.     menu-enable-item(menu, "Create");
  76.     window-menu-adjuster (menu);
  77.     menu-insert(menu);
  78.     menu-draw();
  79.     menu;
  80. end method;
  81.  
  82. define variable *window-menu* = make-window-menu ();
  83.  
  84. /*
  85. {an anonymous method ()
  86.     ("unbinding-begin 1
  87.         ("local-bind
  88.             ((menu (make <menu>
  89.                 #"title" "Window"
  90.                 #"id" 1000
  91.                 #"items" (quote ("Create" "Destroy" "-" "Show" "Hide"))
  92.                 #"behavior" window-menu-behavior
  93.                 #"adjuster" window-menu-adjuster))))
  94.         (menu-enable-item menu "Create")
  95.         (window-menu-adjuster menu)
  96.         (menu-insert menu)
  97.         (menu-draw)
  98.         menu)}
  99. */
  100.